/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.hugo.senai.view;

import br.com.hugo.senai.classes.Configuracoes;
import br.com.hugo.senai.entities.Alternativa;
import br.com.hugo.senai.entities.Conteudo;
import br.com.hugo.senai.entities.Curso;
import br.com.hugo.senai.entities.Disciplina;
import br.com.hugo.senai.dao.Hibernate;
import br.com.hugo.senai.entities.Objetivo;
import br.com.hugo.senai.entities.Questao;
import java.awt.CardLayout;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 *
 * @author Simulado
 */
public class CadastroQuestao extends javax.swing.JFrame {

    //Questao questao = new Questao();
    Alternativa alternativa1 = new Alternativa();
    Alternativa alternativa2 = new Alternativa();
    Alternativa alternativa3 = new Alternativa();
    Alternativa alternativa4 = new Alternativa();

    public CadastroQuestao() {

        initComponents();

        super.setTitle(new Configuracoes().SYSTEM_NAME + super.getTitle());
        this.setIconImage(new Configuracoes().SYSTEM_ICON);

        cbQuestaoCurso.removeAllItems();

        List<Curso> cursos = Hibernate.listAll(Curso.class);

        for (Curso curso : cursos) {
            cbQuestaoCurso.addItem(curso);
        }
//
//        if (Menu.idQuestao != 0) {
//            bQuestao.setVisible(false);
//            bQuestaoAtualizar.setVisible(true);
//
//            questao = (Questao) Hibernate.get(Questao.class, Menu.idQuestao);
//            taEnunciado.setText(questao.getEnunciado());
//            cbAlternativa.setSelected(!questao.isAlternativa());
//            taObjetivo.setText(questao.getObjetivo().toString());
//            cbProvao.setEnabled(questao.isProvao());
//            if (questao.getImagem() != null) {
//                lImg.setIcon(new ImageIcon(       new ImageIcon (        questao.getImagem()         ).getImage().getScaledInstance(100, 200, Image.SCALE_DEFAULT)               ));
//            }
//
//            if (cbAlternativa.isSelected()) {
//                CardLayout card = (CardLayout) root.getLayout();
//                card.show(root, "pResposta");
//                taResposta.setText(questao.getResposta());
//            }
//
//            List<Alternativa> alternativas = Hibernate.listAll(Alternativa.class, questao, "questao");
//
//            if (!alternativas.isEmpty()) {
//                alternativa1 = alternativas.get(0);
//                alternativa2 = alternativas.get(1);
//                alternativa3 = alternativas.get(2);
//                alternativa4 = alternativas.get(3);
//
//                tfQuestao1.setText(alternativa1.getDescricao());
//                a1.setSelected(alternativa1.isAlt_correta());
//
//                tfQuestao2.setText(alternativa2.getDescricao());
//                a2.setSelected(alternativa2.isAlt_correta());
//
//                tfQuestao3.setText(alternativa3.getDescricao());
//                a3.setSelected(alternativa3.isAlt_correta());
//
//                tfQuestao4.setText(alternativa4.getDescricao());
//                a4.setSelected(alternativa4.isAlt_correta());
//
//            }
//
//        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jFileChooser1 = new javax.swing.JFileChooser();
        jScrollPane3 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taEnunciado = new javax.swing.JTextArea();
        cbAlternativa = new javax.swing.JCheckBox();
        lImg = new javax.swing.JLabel();
        root = new javax.swing.JPanel();
        pAlternativa = new javax.swing.JPanel();
        tfQuestao4 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        tfQuestao3 = new javax.swing.JTextField();
        tfQuestao2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tfQuestao1 = new javax.swing.JTextField();
        a1 = new javax.swing.JRadioButton();
        a2 = new javax.swing.JRadioButton();
        a3 = new javax.swing.JRadioButton();
        a4 = new javax.swing.JRadioButton();
        pResposta = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        taResposta = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        cbQuestaoCurso = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        cbQuestaoMateria = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        cbQuestaoConteudo = new javax.swing.JComboBox();
        cbProvao = new javax.swing.JCheckBox();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        taObjetivo = new javax.swing.JTextArea();
        jScrollPane5 = new javax.swing.JScrollPane();
        taObjetivo1 = new javax.swing.JTextArea();
        bQuestao = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        bQuestao1 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("- Cadastro de questão");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setText("Escreva o enunciado:");

        taEnunciado.setColumns(20);
        taEnunciado.setRows(5);
        jScrollPane1.setViewportView(taEnunciado);

        cbAlternativa.setText("Sem alternativas");
        cbAlternativa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbAlternativaActionPerformed(evt);
            }
        });

        lImg.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        lImg.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lImg.setText("FOTO");
        lImg.setToolTipText("Insira uma foto pelo botão");
        lImg.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        lImg.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        root.setLayout(new java.awt.CardLayout());

        jLabel5.setText("d:");

        jLabel4.setText("c:");

        jLabel3.setText("b:");

        jLabel2.setText("a:");

        buttonGroup1.add(a1);
        a1.setText("Alternativa correta");

        buttonGroup1.add(a2);
        a2.setText("Alternativa correta");

        buttonGroup1.add(a3);
        a3.setText("Alternativa correta");

        buttonGroup1.add(a4);
        a4.setText("Alternativa correta");

        javax.swing.GroupLayout pAlternativaLayout = new javax.swing.GroupLayout(pAlternativa);
        pAlternativa.setLayout(pAlternativaLayout);
        pAlternativaLayout.setHorizontalGroup(
            pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pAlternativaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel2)
                        .addComponent(jLabel3))
                    .addComponent(jLabel4)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfQuestao1)
                    .addComponent(tfQuestao2)
                    .addComponent(tfQuestao3, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfQuestao4, javax.swing.GroupLayout.PREFERRED_SIZE, 316, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pAlternativaLayout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(a2)
                            .addComponent(a1)))
                    .addGroup(pAlternativaLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(a4)
                            .addComponent(a3))))
                .addContainerGap(102, Short.MAX_VALUE))
        );
        pAlternativaLayout.setVerticalGroup(
            pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pAlternativaLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfQuestao1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(a1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfQuestao2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(a2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfQuestao3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(a3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pAlternativaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfQuestao4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(a4))
                .addGap(20, 20, 20))
        );

        root.add(pAlternativa, "pAlternativa");

        taResposta.setColumns(20);
        taResposta.setRows(5);
        jScrollPane2.setViewportView(taResposta);

        javax.swing.GroupLayout pRespostaLayout = new javax.swing.GroupLayout(pResposta);
        pResposta.setLayout(pRespostaLayout);
        pRespostaLayout.setHorizontalGroup(
            pRespostaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pRespostaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 438, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(117, Short.MAX_VALUE))
        );
        pRespostaLayout.setVerticalGroup(
            pRespostaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pRespostaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        root.add(pResposta, "pResposta");

        jLabel6.setText("FILTRAR TIPO DE QUESTÃO: ");

        jLabel7.setText("CURSO:");

        cbQuestaoCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbQuestaoCursoActionPerformed(evt);
            }
        });

        jLabel8.setText("DISCIPLINA:");

        cbQuestaoMateria.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cbQuestaoMateriaMouseClicked(evt);
            }
        });
        cbQuestaoMateria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbQuestaoMateriaActionPerformed(evt);
            }
        });

        jLabel9.setText("CONTEÚDO:");

        cbProvao.setText("Questão de Provão");
        cbProvao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbProvaoActionPerformed(evt);
            }
        });

        jLabel10.setText("Objetivo (opcional):");

        jScrollPane4.setOpaque(false);

        taObjetivo.setColumns(20);
        taObjetivo.setRows(5);
        taObjetivo.setBorder(null);
        taObjetivo.setDoubleBuffered(true);
        taObjetivo.setSelectionColor(new java.awt.Color(255, 0, 0));
        jScrollPane4.setViewportView(taObjetivo);

        jScrollPane5.setOpaque(false);

        taObjetivo1.setColumns(20);
        taObjetivo1.setRows(5);
        taObjetivo1.setBorder(null);
        taObjetivo1.setDoubleBuffered(true);
        taObjetivo1.setOpaque(false);
        taObjetivo1.setSelectionColor(new java.awt.Color(255, 0, 0));
        jScrollPane5.setViewportView(taObjetivo1);

        bQuestao.setText("CADASTRAR");
        bQuestao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bQuestaoActionPerformed(evt);
            }
        });

        jButton2.setText("Remover");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        bQuestao1.setText("CANCELAR");
        bQuestao1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bQuestao1ActionPerformed(evt);
            }
        });

        jButton1.setText("Inserir imagem");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel10)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 648, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jButton1)
                                .addComponent(lImg, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 374, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(34, 34, 34)
                                .addComponent(bQuestao, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(63, 63, 63)
                                .addComponent(bQuestao1, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel6)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbQuestaoCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbQuestaoMateria, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbQuestaoConteudo, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(1, 1, 1)
                                        .addComponent(cbAlternativa)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cbProvao))
                                    .addComponent(root, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton2)))
                        .addContainerGap(143, Short.MAX_VALUE))))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cbQuestaoConteudo, cbQuestaoCurso, cbQuestaoMateria});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7)
                    .addComponent(cbQuestaoCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbQuestaoMateria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(cbQuestaoConteudo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lImg, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(cbAlternativa)
                    .addComponent(cbProvao)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(root, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bQuestao)
                    .addComponent(bQuestao1))
                .addContainerGap(70, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cbQuestaoConteudo, cbQuestaoCurso, cbQuestaoMateria});

        jScrollPane3.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(jScrollPane3)
                .addGap(0, 0, 0))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        setSize(new java.awt.Dimension(787, 636));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents
    File file;

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        jFileChooser1.setFileFilter(new FileNameExtensionFilter("Images", "png", "jpg"));

        if (jFileChooser1.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {

            file = jFileChooser1.getSelectedFile();

            lImg.setIcon(new ImageIcon(new ImageIcon(file.getAbsolutePath()).getImage().getScaledInstance(lImg.getWidth(), lImg.getHeight(), Image.SCALE_DEFAULT)));
            lImg.setText("");
        } else {
            file = null;
        }


    }//GEN-LAST:event_jButton1ActionPerformed

    public void cadastrar() {
        Questao questao = new Questao();

        questao.setConteudo((Conteudo) cbQuestaoConteudo.getSelectedItem());

        if(!taObjetivo.getText().isEmpty()){
        Objetivo objetivo = new Objetivo();
        objetivo.setDescricao(taObjetivo.getText());
        questao.setObjetivo(objetivo);
        }

        questao.setEnunciado(taEnunciado.getText());
        questao.setAlternativa(!cbAlternativa.isSelected());

        questao.setProvao(cbProvao.isSelected());
        questao.setResposta(taResposta.getText());

        if (file != null) {
            try {
                questao.setImagem(Questao.converte(file));
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(null, "imagem não pode ser salva", "RESPOSTA", JOptionPane.WARNING_MESSAGE);
            }
        }

        List<Alternativa> alternativas = new ArrayList<Alternativa>();

        if (questao.isAlternativa()) {
            taResposta.setText("");

            alternativa1.setDescricao(tfQuestao1.getText());
            alternativa1.setAlt_correta(a1.isSelected());
            alternativa1.setQuestao(questao);
            alternativas.add(alternativa1);

            alternativa2.setDescricao(tfQuestao2.getText());
            alternativa2.setAlt_correta(a2.isSelected());
            alternativa2.setQuestao(questao);

            alternativas.add(alternativa2);

            alternativa3.setDescricao(tfQuestao3.getText());
            alternativa3.setAlt_correta(a3.isSelected());
            alternativa3.setQuestao(questao);

            alternativas.add(alternativa3);

            alternativa4.setDescricao(tfQuestao4.getText());
            alternativa4.setAlt_correta(a4.isSelected());
            alternativa4.setQuestao(questao);

            alternativas.add(alternativa4);

            questao.setAlternativas(alternativas);

            Hibernate.save(questao);

            JOptionPane.showMessageDialog(null, "Salvo com sucesso!!", "RESPOSTA", JOptionPane.INFORMATION_MESSAGE);
        }else{
            Hibernate.save(questao);
        }

        dispose();
        new CadastroQuestao().setVisible(true);

    }
    private void bQuestaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bQuestaoActionPerformed
        if (!taEnunciado.getText().isEmpty()) {

            if (!cbAlternativa.isSelected()) {
                if (!tfQuestao1.getText().isEmpty() && !tfQuestao2.getText().isEmpty() && !tfQuestao3.getText().isEmpty() && !tfQuestao4.getText().isEmpty()) {
                    cadastrar();
                } else {
                    JOptionPane.showMessageDialog(null, "INSIRA AS ALTERNATIVAS DA QUESTÃO!");
                }

            } else if (!taResposta.getText().isEmpty()) {
                cadastrar();
            } else {
                JOptionPane.showMessageDialog(null, "INSIRA A RESPOSTA DA QUESTÃO!");
            }

        } else {
            JOptionPane.showMessageDialog(null, "INSIRA O ENUNCIADO DA QUESTÃO!");
        }


    }//GEN-LAST:event_bQuestaoActionPerformed

    public void cadastrarQuestoes() {

    }
    private void cbAlternativaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAlternativaActionPerformed
        if (cbAlternativa.isSelected()) {
            CardLayout card = (CardLayout) root.getLayout();
            card.show(root, "pResposta");
        } else {
            CardLayout card = (CardLayout) root.getLayout();
            card.show(root, "pAlternativa");

        }
    }//GEN-LAST:event_cbAlternativaActionPerformed

    private void cbQuestaoCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbQuestaoCursoActionPerformed
        cbQuestaoMateria.removeAllItems();

        List<Disciplina> materias = Hibernate.listAll(Disciplina.class, (Curso) cbQuestaoCurso.getSelectedItem(), "curso");

        for (Disciplina materia : materias) {
            cbQuestaoMateria.addItem(materia);
        }

    }//GEN-LAST:event_cbQuestaoCursoActionPerformed

    private void cbQuestaoMateriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbQuestaoMateriaActionPerformed
        cbQuestaoConteudo.removeAllItems();

        List<Conteudo> conteudos = Hibernate.listAll(Conteudo.class, (Disciplina) cbQuestaoMateria.getSelectedItem(), "disciplina");

        for (Conteudo conteudo : conteudos) {
            cbQuestaoConteudo.addItem(conteudo);
        }
    }//GEN-LAST:event_cbQuestaoMateriaActionPerformed

    private void cbQuestaoMateriaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbQuestaoMateriaMouseClicked
//         cbQuestaoConteudo.removeAllItems();
//        
//        List <Conteudo> conteudos =Hibernate.listAll(Conteudo.class, (Materia) cbQuestaoMateria.getSelectedItem(), "materia");
//       
//        for(Conteudo conteudo: conteudos){
//            cbQuestaoMateria.addItem(conteudo);
//        }
    }//GEN-LAST:event_cbQuestaoMateriaMouseClicked

    private void cbProvaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProvaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbProvaoActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        file = null;
        lImg.setIcon(null);
        lImg.setText("FOTO");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void bQuestao1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bQuestao1ActionPerformed
        dispose();
    }//GEN-LAST:event_bQuestao1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CadastroQuestao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CadastroQuestao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CadastroQuestao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadastroQuestao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new CadastroQuestao().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton a1;
    private javax.swing.JRadioButton a2;
    private javax.swing.JRadioButton a3;
    private javax.swing.JRadioButton a4;
    private javax.swing.JButton bQuestao;
    private javax.swing.JButton bQuestao1;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JCheckBox cbAlternativa;
    private javax.swing.JCheckBox cbProvao;
    private javax.swing.JComboBox cbQuestaoConteudo;
    private javax.swing.JComboBox cbQuestaoCurso;
    private javax.swing.JComboBox cbQuestaoMateria;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    public static javax.swing.JLabel lImg;
    private javax.swing.JPanel pAlternativa;
    private javax.swing.JPanel pResposta;
    private javax.swing.JPanel root;
    private static javax.swing.JTextArea taEnunciado;
    private javax.swing.JTextArea taObjetivo;
    private javax.swing.JTextArea taObjetivo1;
    private javax.swing.JTextArea taResposta;
    private javax.swing.JTextField tfQuestao1;
    private javax.swing.JTextField tfQuestao2;
    private javax.swing.JTextField tfQuestao3;
    private javax.swing.JTextField tfQuestao4;
    // End of variables declaration//GEN-END:variables
}
